/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GestaoGradeCurricular.java
 *
 * Created on 21/08/2009, 23:17:53
 */

package siga.visao_academico;

import java.sql.SQLException;
import javax.swing.JOptionPane;
import siga.banco.conexao;
import siga.visao_busca.buscaCurso;
import siga.visao_busca.buscaDisciplina;
import siga.visao_busca.buscaGradeCurricular;
import siga.visao.index;
import siga.visao.verErros;

/**
 *
 * @author rafaelfrasson
 */
public class GestaoGradeCurricular extends javax.swing.JInternalFrame {
    Object[] JOopcoes = {"Sim","Não"};
    /** Creates new form GestaoGradeCurricular */
    public GestaoGradeCurricular() {
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jpPGradeCurric = new javax.swing.JPanel();
        barraFerramentaFonecedor = new javax.swing.JToolBar();
        btNovo = new javax.swing.JButton();
        btAlterar = new javax.swing.JButton();
        btCancelar = new javax.swing.JButton();
        btSalvar = new javax.swing.JButton();
        btRemover = new javax.swing.JButton();
        btSair1 = new javax.swing.JButton();
        btSair = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jtfGradC = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jtfCodCurso = new javax.swing.JTextField();
        jtfDesCurso = new javax.swing.JTextField();
        jbBuscar = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jtfRegime = new javax.swing.JComboBox();
        jPanel1 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jtfCodFase = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jtfCodDisciplina = new javax.swing.JTextField();
        jtfDesDisciplina = new javax.swing.JTextField();
        jbBuscar1 = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jtfOrdem = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jtfPreReq = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtGrade = new javax.swing.JTable();

        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("Grade Curricular");
        setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/planopag_16x16.png"))); // NOI18N
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameClosed(evt);
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameOpened(evt);
            }
        });

        jpPGradeCurric.setName("jpPGradeCurric"); // NOI18N

        barraFerramentaFonecedor.setFloatable(false);
        barraFerramentaFonecedor.setRollover(true);
        barraFerramentaFonecedor.setName("barraFerramentaFonecedor"); // NOI18N

        btNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/novo_32x32.png"))); // NOI18N
        btNovo.setMnemonic('N');
        btNovo.setText("Novo");
        btNovo.setToolTipText("Inseri um Novo Cadastro");
        btNovo.setFocusable(false);
        btNovo.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btNovo.setMargin(new java.awt.Insets(2, 2, 2, 4));
        btNovo.setName("btNovo"); // NOI18N
        btNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btNovoActionPerformed(evt);
            }
        });
        barraFerramentaFonecedor.add(btNovo);

        btAlterar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/editar_32x32.png"))); // NOI18N
        btAlterar.setMnemonic('A');
        btAlterar.setText("Alterar");
        btAlterar.setToolTipText("Alterar um  Cadastro");
        btAlterar.setEnabled(false);
        btAlterar.setFocusable(false);
        btAlterar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btAlterar.setMargin(new java.awt.Insets(2, 2, 2, 4));
        btAlterar.setName("btAlterar"); // NOI18N
        btAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAlterarActionPerformed(evt);
            }
        });
        barraFerramentaFonecedor.add(btAlterar);

        btCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/cancelar_32x32.png"))); // NOI18N
        btCancelar.setMnemonic('C');
        btCancelar.setText("Cancelar");
        btCancelar.setToolTipText("Cancelar um Cadastro");
        btCancelar.setEnabled(false);
        btCancelar.setFocusable(false);
        btCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btCancelar.setMargin(new java.awt.Insets(2, 2, 2, 4));
        btCancelar.setName("btCancelar"); // NOI18N
        btCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCancelarActionPerformed(evt);
            }
        });
        barraFerramentaFonecedor.add(btCancelar);

        btSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/salvar_32x32.png"))); // NOI18N
        btSalvar.setMnemonic('S');
        btSalvar.setText("Salvar");
        btSalvar.setToolTipText("Salvar um Cadastro");
        btSalvar.setEnabled(false);
        btSalvar.setFocusable(false);
        btSalvar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btSalvar.setMargin(new java.awt.Insets(2, 2, 2, 4));
        btSalvar.setName("btSalvar"); // NOI18N
        btSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSalvarActionPerformed(evt);
            }
        });
        barraFerramentaFonecedor.add(btSalvar);

        btRemover.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/remover_32x32.png"))); // NOI18N
        btRemover.setMnemonic('R');
        btRemover.setText("Remover");
        btRemover.setToolTipText("Remove um Cadastro");
        btRemover.setEnabled(false);
        btRemover.setFocusable(false);
        btRemover.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btRemover.setMargin(new java.awt.Insets(2, 2, 2, 4));
        btRemover.setName("btRemover"); // NOI18N
        btRemover.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btRemoverActionPerformed(evt);
            }
        });
        barraFerramentaFonecedor.add(btRemover);

        btSair1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/buscar_32x32.png"))); // NOI18N
        btSair1.setMnemonic('B');
        btSair1.setText("Busca");
        btSair1.setToolTipText("Busca por Grade Curricular");
        btSair1.setFocusable(false);
        btSair1.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btSair1.setMargin(new java.awt.Insets(2, 2, 2, 4));
        btSair1.setName("btSair1"); // NOI18N
        btSair1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSair1ActionPerformed(evt);
            }
        });
        barraFerramentaFonecedor.add(btSair1);

        btSair.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/sair_32x32.png"))); // NOI18N
        btSair.setMnemonic('S');
        btSair.setText("Sair");
        btSair.setToolTipText("Sair da Janela");
        btSair.setFocusable(false);
        btSair.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btSair.setMargin(new java.awt.Insets(2, 2, 2, 4));
        btSair.setName("btSair"); // NOI18N
        btSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSairActionPerformed(evt);
            }
        });
        barraFerramentaFonecedor.add(btSair);

        jLabel1.setText("Nome da Grade Curricular");
        jLabel1.setName("jLabel1"); // NOI18N

        jtfGradC.setEditable(false);
        jtfGradC.setName("jtfGradC"); // NOI18N

        jLabel2.setText("Curso");
        jLabel2.setName("jLabel2"); // NOI18N

        jtfCodCurso.setEditable(false);
        jtfCodCurso.setName("jtfCodCurso"); // NOI18N

        jtfDesCurso.setEditable(false);
        jtfDesCurso.setName("jtfDesCurso"); // NOI18N

        jbBuscar.setFont(new java.awt.Font("Dialog", 0, 10));
        jbBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/busca_16x16.png"))); // NOI18N
        jbBuscar.setText("Buscar");
        jbBuscar.setEnabled(false);
        jbBuscar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbBuscar.setMargin(new java.awt.Insets(2, 2, 2, 2));
        jbBuscar.setName("jbBuscar"); // NOI18N
        jbBuscar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbBuscarActionPerformed(evt);
            }
        });

        jLabel3.setText("Regime");
        jLabel3.setName("jLabel3"); // NOI18N

        jtfRegime.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Há opções", "Serial", "Semestral", "Modular" }));
        jtfRegime.setEnabled(false);
        jtfRegime.setName("jtfRegime"); // NOI18N

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Inserir Disciplinas"));
        jPanel1.setName("jPanel1"); // NOI18N

        jLabel4.setText("Fase/Serie/Mód");
        jLabel4.setName("jLabel4"); // NOI18N

        jtfCodFase.setEditable(false);
        jtfCodFase.setText("1");
        jtfCodFase.setName("jtfCodFase"); // NOI18N

        jLabel5.setText("Disciplina");
        jLabel5.setName("jLabel5"); // NOI18N

        jtfCodDisciplina.setEditable(false);
        jtfCodDisciplina.setName("jtfCodDisciplina"); // NOI18N

        jtfDesDisciplina.setEditable(false);
        jtfDesDisciplina.setName("jtfDesDisciplina"); // NOI18N

        jbBuscar1.setFont(new java.awt.Font("Dialog", 0, 10));
        jbBuscar1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/busca_16x16.png"))); // NOI18N
        jbBuscar1.setText("Buscar");
        jbBuscar1.setEnabled(false);
        jbBuscar1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbBuscar1.setMargin(new java.awt.Insets(2, 2, 2, 2));
        jbBuscar1.setName("jbBuscar1"); // NOI18N
        jbBuscar1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbBuscar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbBuscar1ActionPerformed(evt);
            }
        });

        jLabel6.setText("Ordem");
        jLabel6.setName("jLabel6"); // NOI18N

        jtfOrdem.setEditable(false);
        jtfOrdem.setText("1");
        jtfOrdem.setName("jtfOrdem"); // NOI18N

        jLabel7.setText("Pré-requisito");
        jLabel7.setName("jLabel7"); // NOI18N

        jtfPreReq.setEditable(false);
        jtfPreReq.setText("0");
        jtfPreReq.setName("jtfPreReq"); // NOI18N

        jButton1.setFont(new java.awt.Font("Dialog", 0, 10));
        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/page_add.png"))); // NOI18N
        jButton1.setText("Inserir");
        jButton1.setToolTipText("Inseri os dados selecionados na Tabela de Disciplinas");
        jButton1.setEnabled(false);
        jButton1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jButton1.setMargin(new java.awt.Insets(2, 2, 2, 2));
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setFont(new java.awt.Font("Dialog", 0, 10));
        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/page_delete.png"))); // NOI18N
        jButton2.setText("Remover");
        jButton2.setToolTipText("Remove a disciplina da lista");
        jButton2.setEnabled(false);
        jButton2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jButton2.setMargin(new java.awt.Insets(2, 2, 2, 2));
        jButton2.setName("jButton2"); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jtfCodFase, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jtfOrdem, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.LEADING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jtfPreReq, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.LEADING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jtfCodDisciplina, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtfDesDisciplina, javax.swing.GroupLayout.DEFAULT_SIZE, 332, Short.MAX_VALUE))
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbBuscar1)
                .addGap(36, 36, 36)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jtfCodDisciplina, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jtfDesDisciplina, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jbBuscar1, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel6)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jtfOrdem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel4)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jtfCodFase, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel7)
                                        .addComponent(jLabel5))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jtfPreReq, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jtGrade.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Fase/Série/Mod", "Ordem", "Código", "Disciplina", "Pré-req."
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, true, false, false, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jtGrade.setName("jtGrade"); // NOI18N
        jScrollPane1.setViewportView(jtGrade);
        jtGrade.getColumnModel().getColumn(0).setPreferredWidth(100);
        jtGrade.getColumnModel().getColumn(0).setMaxWidth(100);
        jtGrade.getColumnModel().getColumn(1).setPreferredWidth(50);
        jtGrade.getColumnModel().getColumn(1).setMaxWidth(50);
        jtGrade.getColumnModel().getColumn(2).setPreferredWidth(70);
        jtGrade.getColumnModel().getColumn(2).setMaxWidth(70);
        jtGrade.getColumnModel().getColumn(4).setPreferredWidth(50);
        jtGrade.getColumnModel().getColumn(4).setMaxWidth(50);

        javax.swing.GroupLayout jpPGradeCurricLayout = new javax.swing.GroupLayout(jpPGradeCurric);
        jpPGradeCurric.setLayout(jpPGradeCurricLayout);
        jpPGradeCurricLayout.setHorizontalGroup(
            jpPGradeCurricLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(barraFerramentaFonecedor, javax.swing.GroupLayout.DEFAULT_SIZE, 951, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpPGradeCurricLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpPGradeCurricLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jtfCodCurso, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtfDesCurso, javax.swing.GroupLayout.DEFAULT_SIZE, 786, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jbBuscar)
                .addContainerGap())
            .addGroup(jpPGradeCurricLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpPGradeCurricLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jtfGradC, javax.swing.GroupLayout.DEFAULT_SIZE, 806, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpPGradeCurricLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jpPGradeCurricLayout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(58, 58, 58))
                    .addGroup(jpPGradeCurricLayout.createSequentialGroup()
                        .addComponent(jtfRegime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
            .addGroup(jpPGradeCurricLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 951, Short.MAX_VALUE)
        );
        jpPGradeCurricLayout.setVerticalGroup(
            jpPGradeCurricLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpPGradeCurricLayout.createSequentialGroup()
                .addComponent(barraFerramentaFonecedor, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpPGradeCurricLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpPGradeCurricLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jpPGradeCurricLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtfGradC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jtfRegime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jpPGradeCurricLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jpPGradeCurricLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jtfDesCurso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jbBuscar))
                            .addGroup(jpPGradeCurricLayout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jtfCodCurso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(jLabel3))
                .addGap(9, 9, 9)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpPGradeCurric, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpPGradeCurric, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btNovoActionPerformed
        btSalvar.setEnabled(!btSalvar.isEnabled());
        btCancelar.setEnabled(!btCancelar.isEnabled());
        btNovo.setEnabled(!btNovo.isEnabled());
        btAlterar.setEnabled(false);
        btRemover.setEnabled(false);
        gerenciaCampos();
        LimpaCampos();
}//GEN-LAST:event_btNovoActionPerformed

    private void btAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAlterarActionPerformed
        gerenciaBotao();
        gerenciaCampos();
}//GEN-LAST:event_btAlterarActionPerformed

    private void btCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelarActionPerformed
        if(btCancelar.isEnabled()){
            if(!btNovo.isEnabled()){
                btSalvar.setEnabled(!btSalvar.isEnabled());
                btCancelar.setEnabled(!btCancelar.isEnabled());
                btNovo.setEnabled(!btNovo.isEnabled());
            }else{
                gerenciaBotao();
            }
            gerenciaCampos();
            LimpaCampos();
        }
}//GEN-LAST:event_btCancelarActionPerformed

    private void btSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSalvarActionPerformed
        if(!jtfGradC.getText().equals("")){
            if(!jtfDesCurso.getText().equals("")){
                if(jtfRegime.getSelectedIndex()!=0){
                    try {
                        conexao.stm.executeUpdate("delete from grade_curricular where cod_curso=" + jtfCodCurso.getText() + " and cod_emp=" + index.cod_emp + "");
                        javax.swing.table.DefaultTableModel jtg = (javax.swing.table.DefaultTableModel) jtGrade.getModel();
                        for (int x = jtGrade.getRowCount() - 1; x >= 0; --x) {
                            conexao.Inserir("replace into grade_curricular(cod_emp,cod_curso,ordem,cod_tipo,cod_disciplina,cod_fase,cod_pre_req,descricao) " +
                                    "values("+index.cod_emp+","+jtfCodCurso.getText()+","+jtg.getValueAt(x, 1)+","+jtfRegime.getSelectedIndex()+","+jtg.getValueAt(x, 2)+","+jtg.getValueAt(x, 0)+","+jtg.getValueAt(x, 4)+",\""+jtfGradC.getText()+"\")");
                        }
                    } catch (SQLException ex) {
                        verErros.setErro(ex.getMessage());
                    }
                    gerenciaBotao();
                    gerenciaCampos();
                    LimpaCampos();
                }else{
                    JOptionPane.showMessageDialog(null, "Campo Regime é obrigatório.","Alerta do Sistema.",JOptionPane.INFORMATION_MESSAGE);
                    jtfRegime.requestFocus();
                }
            }else{
                JOptionPane.showMessageDialog(null, "Campo Curso é obrigatório.","Alerta do Sistema.",JOptionPane.INFORMATION_MESSAGE);
                jtfCodCurso.requestFocus();
            }
        }else{
            JOptionPane.showMessageDialog(null, "Campo Nome da Grade Curricular é obrigatório.","Alerta do Sistema.",JOptionPane.INFORMATION_MESSAGE);
            jtfGradC.requestFocus();
        }
}//GEN-LAST:event_btSalvarActionPerformed

    private void btRemoverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btRemoverActionPerformed
        if (JOptionPane.showOptionDialog(null, "Deseja remover essa Grade Curricular?\nEsta ação implica em remover todos os registros de Ordens do Sistema.", "Removendo Grade Curricular", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, JOopcoes, JOopcoes[0]) == JOptionPane.YES_OPTION) {
            if(!jtfDesCurso.getText().equals("")){
                try {
                    conexao.stm.executeUpdate("delete from grade_curricular where cod_curso="+jtfCodCurso.getText()+" and cod_emp="+index.cod_emp+"");
                } catch (SQLException ex) {
                    verErros.setErro(ex.getMessage());
                }
            }
        }
}//GEN-LAST:event_btRemoverActionPerformed

    private void btSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSairActionPerformed
        btCancelarActionPerformed(evt);
        setVisible(false);
        dispose();
}//GEN-LAST:event_btSairActionPerformed

    private void jbBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbBuscarActionPerformed
        buscaCurso bc = new buscaCurso(null,true);
        bc.setLocation((index.tela.width-bc.getWidth())/2, (index.tela.height-bc.getHeight())/2);
        bc.setVisible(true);
        if(buscaCurso.isConfirmaCurso()){
            jtfCodCurso.setText(index.LRcurso.get(0).toString());
            jtfDesCurso.setText(index.LRcurso.get(1).toString());
        }
        index.LRcurso.add(0,"");
        index.LRcurso.add(1,"");
    }//GEN-LAST:event_jbBuscarActionPerformed

    private void jbBuscar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbBuscar1ActionPerformed
        buscaDisciplina bd = new buscaDisciplina(null,true);
        bd.setLocation((index.tela.width-bd.getWidth())/2, (index.tela.height-bd.getHeight())/2);
        bd.setVisible(true);
        if(!index.LRdisciplina.get(0).equals("")){
            jtfCodDisciplina.setText(index.LRdisciplina.get(0).toString());
            jtfDesDisciplina.setText(index.LRdisciplina.get(1).toString());
        }
        index.LRdisciplina.add(0,"");
        index.LRdisciplina.add(1,"");
    }//GEN-LAST:event_jbBuscar1ActionPerformed

    private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameOpened
        index.LRdisciplina.add(0,"");
        index.LRcurso.add(0,"");
    }//GEN-LAST:event_formInternalFrameOpened

    private void formInternalFrameClosed(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameClosed
        
    }//GEN-LAST:event_formInternalFrameClosed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        if(!jtfCodFase.getText().equals("")){
            if(!jtfOrdem.getText().equals("")){
                if(!jtfPreReq.getText().equals("")){
                    if(!jtfDesDisciplina.getText().equals("")){
                        javax.swing.table.DefaultTableModel jtg = (javax.swing.table.DefaultTableModel) jtGrade.getModel();
                        jtg.addRow(new Object[]{jtfCodFase.getText(),jtfOrdem.getText(),jtfCodDisciplina.getText(),jtfDesDisciplina.getText(),jtfPreReq.getText()});
                    }else{
                         JOptionPane.showMessageDialog(null, "Campo Disciplina é obrigatório.","Alerta do Sistema.",JOptionPane.INFORMATION_MESSAGE);
                        jtfDesDisciplina.requestFocus();
                    }
                }else{
                    JOptionPane.showMessageDialog(null, "Campo Pré-Requisito é obrigatório.","Alerta do Sistema.",JOptionPane.INFORMATION_MESSAGE);
                    jtfPreReq.requestFocus();
                }
            }else{
                JOptionPane.showMessageDialog(null, "Campo Ordem é obrigatório.","Alerta do Sistema.",JOptionPane.INFORMATION_MESSAGE);
                jtfOrdem.requestFocus();
            }
        }else{
            JOptionPane.showMessageDialog(null, "Campo Fase/Série/Módulo é obrigatório.","Alerta do Sistema.",JOptionPane.INFORMATION_MESSAGE);
            jtfCodFase.requestFocus();
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        javax.swing.table.DefaultTableModel jtg = (javax.swing.table.DefaultTableModel) jtGrade.getModel();
        jtg.removeRow(jtGrade.getSelectedRow());
    }//GEN-LAST:event_jButton2ActionPerformed

    private void btSair1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSair1ActionPerformed
        buscaGradeCurricular bgc = new buscaGradeCurricular(null,true);
        bgc.setLocation((index.tela.width-bgc.getWidth())/2, (index.tela.height-bgc.getHeight())/2);
        bgc.setVisible(true);
        if(!index.LRcurso.get(0).equals("")){
            try {
                conexao.Query("select gc.*,gc2.descricao as des_curso, gd.descricao as des_disc from grade_curricular gc " +
                        "inner join grade_curso gc2 on gc2.codigo=gc.cod_curso and gc.cod_emp=gc2.cod_emp " +
                        "inner join grade_disciplina gd on gd.codigo=gc.cod_disciplina and gc.cod_emp=gd.cod_emp " +
                        "where gc.cod_curso=" + index.LRcurso.get(0) + " and gc.cod_emp=" + index.cod_emp + " order by gc.cod_curso,gc.ordem");
                javax.swing.table.DefaultTableModel jtg = (javax.swing.table.DefaultTableModel) jtGrade.getModel();
                for (int x = jtGrade.getRowCount() - 1; x >= 0; --x) {
                    jtg.removeRow(x);
                }
                while(conexao.rs.next()){
                    jtfCodCurso.setText(""+conexao.rs.getString("cod_curso"));
                    jtfDesCurso.setText(""+conexao.rs.getString("des_curso"));
                    jtfGradC.setText(""+conexao.rs.getString("descricao"));
                    jtfRegime.setSelectedIndex(conexao.rs.getInt("cod_tipo"));
                    jtg.addRow(new Object[]{conexao.rs.getString("cod_fase"),conexao.rs.getString("ordem"),conexao.rs.getString("cod_disciplina"),conexao.rs.getString("des_disc"),conexao.rs.getString("cod_pre_req")});
                }
            } catch (SQLException ex) {
                verErros.setErro(ex.getMessage());
            }
        }
        index.LRcurso.add(0, "");
        if(btNovo.isEnabled()){
            btAlterar.setEnabled(true);
            btRemover.setEnabled(true);
        }
    }//GEN-LAST:event_btSair1ActionPerformed

    private void gerenciaCampos(){
        jtfCodCurso.setEditable(!jtfGradC.isEditable());
        jtfCodFase.setEditable(!jtfGradC.isEditable());
        jtfOrdem.setEditable(!jtfGradC.isEditable());
        jtfCodDisciplina.setEditable(!jtfGradC.isEditable());
        jtfPreReq.setEditable(!jtfGradC.isEditable());
        jtfRegime.setEnabled(!jtfRegime.isEnabled());
        jtfGradC.setEditable(!jtfGradC.isEditable());
        jbBuscar1.setEnabled(!jbBuscar.isEnabled());
        jButton1.setEnabled(!jbBuscar.isEnabled());
        jButton2.setEnabled(!jbBuscar.isEnabled());
        jbBuscar.setEnabled(!jbBuscar.isEnabled());
    }

    private void gerenciaBotao(){
        btNovo.setEnabled(!btNovo.isEnabled());
        btAlterar.setEnabled(!btAlterar.isEnabled());
        btCancelar.setEnabled(!btCancelar.isEnabled());
        btRemover.setEnabled(!btRemover.isEnabled());
        btSalvar.setEnabled(!btSalvar.isEnabled());
    }

    private void LimpaCampos(){
        jtfCodCurso.setText("");
        jtfDesCurso.setText("");
        jtfCodFase.setText("");
        jtfOrdem.setText("");
        jtfCodDisciplina.setText("");
        jtfDesDisciplina.setText("");
        jtfPreReq.setText("");
        jtfGradC.setText("");
        jtfRegime.setSelectedIndex(0);
        javax.swing.table.DefaultTableModel jtg = (javax.swing.table.DefaultTableModel) jtGrade.getModel();
        for (int x = jtGrade.getRowCount() - 1; x >= 0; --x) {
            jtg.removeRow(x);
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JToolBar barraFerramentaFonecedor;
    private javax.swing.JButton btAlterar;
    private javax.swing.JButton btCancelar;
    private javax.swing.JButton btNovo;
    private javax.swing.JButton btRemover;
    private javax.swing.JButton btSair;
    private javax.swing.JButton btSair1;
    private javax.swing.JButton btSalvar;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbBuscar;
    private javax.swing.JButton jbBuscar1;
    private javax.swing.JPanel jpPGradeCurric;
    private javax.swing.JTable jtGrade;
    private javax.swing.JTextField jtfCodCurso;
    private javax.swing.JTextField jtfCodDisciplina;
    private javax.swing.JTextField jtfCodFase;
    private javax.swing.JTextField jtfDesCurso;
    private javax.swing.JTextField jtfDesDisciplina;
    private javax.swing.JTextField jtfGradC;
    private javax.swing.JTextField jtfOrdem;
    private javax.swing.JTextField jtfPreReq;
    private javax.swing.JComboBox jtfRegime;
    // End of variables declaration//GEN-END:variables

}
